/**
 * @(#)SimulatorTaskVerDAOImpl.java 2016年12月1日
 * Copyright(C) 2016 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.jsbd.boss.common.redis.RedisClient;
import org.jsbd.boss.dao.ISimulatorSysVerDAO;
import org.jsbd.boss.domian.SysVerVO;
import org.jsbd.boss.domian.channel.SimulatorSysVer;
import org.jsbd.boss.service.ISimulatorSysVerService;
import org.jsbd.boss.util.CacheKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * 模拟器版本号
 * 
 * @author <a href="mailto:xupengcheng@zhexinit.com" >徐鹏程</a>
 * @version 1.0.0
 */
@Service
public class SimulatorSysVerServiceImpl implements ISimulatorSysVerService {
	public static final Logger LOGGER = LoggerFactory.getLogger(SimulatorSysVerServiceImpl.class);

	@Resource
	private ISimulatorSysVerDAO simulatorSysVerDAO;
	@Resource
	private RedisClient redisClient;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.jsbd.boss.dao.ISimulatorSysVerDAO#insertSimulatorTaskVer(org.jsbd
	 * .boss.domian.channel.SimulatorSysVer)
	 */
	@Override
	public Integer insertSimulatorSysVer(SimulatorSysVer simulatorSysVer) {
		return simulatorSysVerDAO.insertSimulatorSysVer(simulatorSysVer);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.jsbd.boss.dao.ISimulatorSysVerDAO#selectSimulatorSysVer(java.lang
	 * .String)
	 */
	@Override
	public List<SimulatorSysVer> selectSimulatorSysVer(String ver) {
		return simulatorSysVerDAO.selectSimulatorSysVer(ver);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.jsbd.boss.dao.ISimulatorSysVerDAO#delSimulatorTaskVer(java.lang.String
	 * )
	 */
	@Override
	public int delSimulatorSysVer(String ver) {
		return simulatorSysVerDAO.delSimulatorSysVer(ver);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.jsbd.boss.service.ISimulatorSysVerService#selectAllSimulatorSysVer()
	 */
	@Override
	public List<SimulatorSysVer> selectAllSimulatorSysVer() {
		Object obj = redisClient.get(CacheKey.V_LIST);
		if (obj != null) {
			return (List<SimulatorSysVer>) obj;
		} else {
			List<SimulatorSysVer> list = simulatorSysVerDAO.selectSimulatorSysVer(null);
			if (list != null) {
				redisClient.put(CacheKey.V_LIST, list, 300);
			} else {
				redisClient.put(CacheKey.V_LIST, new ArrayList<>(), 300);
			}
			return list;
		}
	}

	@Override
	public Integer updateSimulatorSysVer(SimulatorSysVer simulatorSysVer) {
		return simulatorSysVerDAO.updateSimulatorSysVer(simulatorSysVer);
	}

	/**
	 * 
	 * 获取所有版本列表
	 * @author <a href="mailto:zhouchao@xingbook.com" >周超</a>
	 * @return
	 */
	public List<String> getSysVerStringList(){
		List<SimulatorSysVer> list = simulatorSysVerDAO.selectSimulatorSysVer(null);
		if(list==null||list.isEmpty()){
			return null;
		}
		List<String> resultList=new ArrayList<String>();
		
		for(SimulatorSysVer sysVer:list){
			resultList.add(sysVer.getVer());
		}
		return resultList;
	}

	@Override
	public List<SimulatorSysVer> selectSimulatorSysVerByVO(SysVerVO svVO) {
		return simulatorSysVerDAO.selectSimulatorSysVerByVO(svVO);
	}
	
}
